#library(devtools) #necessary for install_github function
#install_github("jonathon-love/jsq") #install jsq package
library(jsq)

# Set working directory
setwd("/Users/jon_r/OneDrive/Documenten/University of Cambridge/Psychology")

# Load datasets
longfake <- read.csv("long_dataperceivedgroup.csv")
widefake <- read.csv("complete_data.csv")

library(BayesFactor)

longfake$Group <- as.factor(longfake$Group)
longfake$time <- as.factor(longfake$time)
longfake$Session.ID <- as.factor(longfake$Session.ID)

bayes_model <- lmBF(PerceivedReliability ~ Group + time + Group*time, whichRandom = "Session.ID", data=longfake)

bayes_ttest <- ttestBF(x=widefake$DiffPre, y=widefake$DiffPost, paired=TRUE)
bayes_ttest
plot(bayes_ttest[,"mu"])

bayes_model

bayes_anova <- banova(
  data = longfake,
  dep = PerceivedReliability,
  factors = vars(Group, time),
  random = Session.ID,
  effects = TRUE,
  modelTerms = list(
    list(
      components="Group",
      isNuisance=FALSE),
    list(
      components="time",
      isNuisance=FALSE),
    list(
      components="Session.ID",
      isNuisance=TRUE),
    list(
      components=c("Group", "time"),
      isNuisance=FALSE)),
  postHoc = vars())

bayes_anova

bayes_ttest <- bttestPS(
  data = data,
  pairs = list(
    list(
      i1="FactsPre",
      i2="FactsPost"),
    list(
      i1="FakePre",
      i2="FakePost"),
    list(
      i1="DiffPre",
      i2="DiffPost")),
  bfType = "BF01",
  plotPP = TRUE,
  plotRobust = TRUE,
  plotDesc = TRUE)

bayes_ttest
